package engine.logic.login
{
	import flash.display.MovieClip;

	public class RoleCreateGroup implements ILoginUI
	{
		private var _castleSelectUI:ILoginUI;
		private var _roleCreateUI	:ILoginUI;
		
		private var _completeCallBack:Function;
		
		private var _roleRaceId:int;
		private var _roleCastleId:int;
		
		private var _roleOccupationId:int;
		private var _roleName:String
		
		public function RoleCreateGroup(mc:MovieClip,_loginContainer:MovieClip)
		{
			
			_castleSelectUI=new CastleSelectUI(mc.castleSelectUI as MovieClip,_loginContainer);
			_castleSelectUI.completeCallBack=castleSelectCompleteCB;
			
			_roleCreateUI=new RoleCreateUI(mc.roleCreateUI as MovieClip,_loginContainer);
			_roleCreateUI.completeCallBack=roleCreateCompleteCB;
			
		}
		
		public function show(info:Object=null):void
		{
			_castleSelectUI.show();
		}
		
		public function hide():void
		{
			_roleCreateUI.hide();
		}
		
		public function recycle():void
		{
			if(	null	!=	_roleCreateUI)
			{
				_roleCreateUI.hide();
			}
			
			if(	null	!=	_castleSelectUI)
			{
				_castleSelectUI.hide();
			}
			
			_roleCreateUI	=	null;
			_castleSelectUI	=	null;
		}
		
		public function set completeCallBack(cb:Function):void
		{
			_completeCallBack=cb;
		}
		
		private function castleSelectCompleteCB(info:Object):void
		{
			_roleRaceId=info.raceId;
			_roleCastleId=info.castleId;
			CastleSelectUI(info.target).hide();
			_roleCreateUI.show({raceId:_roleRaceId});
		}
		
		private function roleCreateCompleteCB(info:Object):void
		{
			if(RoleCreateUI.Action_Last	==	info.action)
			{
				_roleCreateUI.hide();
				_castleSelectUI.show();
			}
			else if(RoleCreateUI.Action_Next	==	info.action)
			{
				_roleRaceId=info.raceId;
				_roleOccupationId=info.occuId;
				_roleName=info.roleName;
				
				//send message
				//				SystemSender.getInstance().CreatRole(_roleName,_roleRaceId,_roleSex,0,this._roleOccupationId);
				
				if(	null	!=	_completeCallBack)
				{
					var groupfbInfo:Object={
						castleId:_roleCastleId,
						raceId	:_roleRaceId,
						occuId	:_roleOccupationId,
						roleName:_roleName
					};
					
					_completeCallBack(groupfbInfo);
				}
				
			}
		}
	}
}